<?php
	header('Content-type: application/xls');
header("Content-Disposition:attachment;filename=ketquaBHLĐ.xls");

?>
<?php
    echo $others->conghoa($tendv ['Zdv'] ['tendvcha'] ,$tendv ['Zdv'] ['tendv'],3,4,'Kết quả bán hàng lưu động'); 
?>
<?php if(!empty($hanghoabhlds) && !empty($chitieungaybhlds)) {?>
			<table border="1">
				<tr>
				<th rowspan="3" style="background: #d5d5d5; font-weight: bold">STT</th>
				<th rowspan="3" style="background: #d5d5d5; font-weight: bold">Trung Tâm</th>
				<th rowspan="3" style="background: #d5d5d5; font-weight: bold">Nhân Viên</th>
				<th rowspan="3" style="background: #d5d5d5; font-weight: bold">Đội</th>
				<th rowspan="3"  style="background: #d5d5d5; font-weight: bold">Địa Điểm</th>
				<th rowspan="3" style="background: #d5d5d5; font-weight: bold">Ngày</th>
				<th rowspan="3"  style="background: #d5d5d5; font-weight: bold">Thành viên tham gia</th>
				<th colspan="<?php echo count($hanghoabhlds)*3?>" 
                        style="background: #d5d5d5; font-weight: bold" >Chỉ tiêu</th>
				<th rowspan="3" style="background: #d5d5d5; font-weight: bold">Ghi chú</th>
				
				</tr>
				<tr>
				<?php foreach ($hanghoabhlds as $keyhh =>$valhh):?>
				<th colspan=3><?php echo $valhh ?></th>
				<?php endforeach;?>
				</tr>
				<tr>
				<?php foreach ($hanghoabhlds as $keyhh =>$valhh):?>
				<th>Chỉ<br>Tiêu</th>
				<th>Kết<br> quả</th>
				<th>% <br>Hoàn<br> Thành </th>
				<?php endforeach;?>
				</tr>
				<?php
					$i=0; 
					 foreach ($chitieungaybhlds as $chitieungay):
					  $i++;
				?>
				<tr>
				<td><?php echo $i?></td>
				<td><?php echo $chitieungay['Nhanvien']['Donvi']['madv']?></td>
				<td><?php echo $chitieungay['Nhanvien']['tennv']?></td>
				<td><?php echo $chitieungay['Kehoachbhld']['tendoi']?></td>
				<td><?php echo $chitieungay['Kehoachbhld']['diadiem']?></td>
				<td><?php echo date('d-m-Y',strtotime($chitieungay['Kehoachbhld']['thoigian']))?></td>
				<td><?php echo $chitieungay['Kehoachbhld']['nhansu']?></td>
				<?php foreach ($hanghoabhlds as $keyhh =>$valhh):?>
				<td>
				<?php
					foreach ($chitieungay['Chitieungay'] as $ctngay)
					{
						if($ctngay['hanghoa_id']==$keyhh)
				 			echo $ctngay['soluong'];	
					}
				?>
				</td>
				<td>
				<?php
					foreach ($chitieungay['Chitieungay'] as $ctngay)
					{
						if($ctngay['hanghoa_id']==$keyhh)
				 			echo $ctngay['ketqua'];	
					}
				?>
				</td>
				<td>
				<?php
					foreach ($chitieungay['Chitieungay'] as $ctngay)
					{
						if($ctngay['hanghoa_id']==$keyhh)
				 			echo number_format(round($ctngay['ketqua']*100/$ctngay['soluong'],2),0,',','.');	
					}
				?>
				</td>
				<?php endforeach;?>
				<td><?php echo $chitieungay['Kehoachbhld']['ghichu']?></td>
				</tr>
				<?php endforeach;?> 
				</table>
					<?php }
					else
					{
					?>
					<h3>Không có dữ liệu</h3>
					<?php }?>